package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//购物车
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车接口")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO dto){
        log.info("添加购物车：{}", dto);
        return shoppingCartService.add(dto);
    }

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result lsit(){
        return shoppingCartService.list();
    }
    @DeleteMapping("/clean")
    @ApiOperation("删除购物车")
    public Result clean(){
        return shoppingCartService.clean();
    }

    /**
     * 删除一个购物车
     * @return
     */
    @ApiOperation("删除一个购物车")
    @PostMapping("/sub")
    public Result deleteOne(@RequestBody ShoppingCart dao){
        return shoppingCartService.deleteOne(dao);
    }
}
